package com.hrm.job.dao.provider;

import java.util.HashMap;

import org.apache.ibatis.jdbc.SQL;

public class JobSqlProvider {
	public String selectJob(HashMap<Object, Object> map){
		StringBuffer sql = new StringBuffer();
		sql.append("select * from job_inf ");
		if(map.get("name") != null && !map.get("name").equals("")){
			sql.append("where name like '%' #{name} '%' ");
		}
		sql.append("limit #{start},#{pageSize}");
		return sql.toString();
	}
	
	public String selectJobCount(String name){
		String sql = new SQL(){
			{
			this.SELECT("count(*)");
			this.FROM("job_inf");
			if(name != null && !name.equals("")){
				this.WHERE("name like '%' #{name} '%'");
			}
		}
	}.toString();
	return sql;
	}
	
	public String deleteJob(HashMap<Object, Object> map){
		Integer[] ids = (Integer[]) map.get("ids");
		StringBuffer sql = new StringBuffer();
		//delete from job_inf where id in (ids[0],ids[1],ids[2])
		sql.append("delete from job_inf where id in (");
		for(Integer id:ids){
			sql.append(id+",");
		}
		sql.deleteCharAt(sql.length()-1);
		sql.append(")");
		return sql.toString();
	}
}
